﻿<ui:DialogWindow x:Class="CodeStash.Addin.Views.SearchView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:ui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.10.0"
                 xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0"
                 xmlns:views="clr-namespace:CodeStash.Addin.Views"
                 xmlns:conv="clr-namespace:CodeStash.Addin.ValueConverters"
                 xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
                 xmlns:core="clr-namespace:CodeStash.Addin.Core;assembly=CodeStash.Addin.Core"
                 xmlns:cinch="clr-namespace:Cinch;assembly=Cinch.WPF"
                 xmlns:controls="clr-namespace:CodeStash.Addin.Controls;assembly="
                 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
                 x:Name="theView"
                 Title="Search"
                 Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}"
                 Foreground="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowTextKey}}"
                 WindowStartupLocation="CenterScreen"
                 ShowInTaskbar="False"
                 Height="640"
                 Width="640">


    <ui:DialogWindow.Resources>

        <ImageSource PresentationOptions:Freeze="true"
                     x:Key="logoImage">/CodeStash.Addin;component/Images/Logo.png</ImageSource>


        <Style TargetType="{x:Type RadioButton}">
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="VerticalContentAlignment"
                    Value="Center" />
            <Setter Property="Height"
                    Value="23" />
            <Setter Property="Margin"
                    Value="5" />
            <Setter Property="Padding"
                    Value="0" />
        </Style>


        <Style TargetType="{x:Type Label}">
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="VerticalContentAlignment"
                    Value="Center" />
            <Setter Property="Height"
                    Value="Auto" />
            <Setter Property="Margin"
                    Value="5,2,5,2" />
            <Setter Property="Padding"
                    Value="0" />
        </Style>

        <Style TargetType="{x:Type TextBox}">
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="HorizontalAlignment"
                    Value="Stretch" />
            <Setter Property="Height"
                    Value="23" />
            <Setter Property="Margin"
                    Value="5" />
            <Setter Property="Padding"
                    Value="0" />
        </Style>

        <Style TargetType="{x:Type ComboBox}">
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="VerticalContentAlignment"
                    Value="Center" />
            <Setter Property="HorizontalAlignment"
                    Value="Stretch" />
            <Setter Property="HorizontalContentAlignment"
                    Value="Left" />
            <Setter Property="Height"
                    Value="23" />
            <Setter Property="Margin"
                    Value="5" />
            <Setter Property="Padding"
                    Value="0" />
        </Style>

        <Style TargetType="{x:Type Button}">
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="HorizontalAlignment"
                    Value="Left" />
            <Setter Property="Margin"
                    Value="5" />
            <Setter Property="Padding"
                    Value="0" />
        </Style>

        <Style x:Key="comboLabels"
               TargetType="{x:Type Label}">
            <Setter Property="VerticalAlignment"
                    Value="Center" />
            <Setter Property="VerticalContentAlignment"
                    Value="Center" />
            <Setter Property="HorizontalAlignment"
                    Value="Left" />
            <Setter Property="HorizontalContentAlignment"
                    Value="Left" />
            <Setter Property="Margin"
                    Value="5" />
            <Setter Property="Padding"
                    Value="0" />
        </Style>


    </ui:DialogWindow.Resources>


    <Grid x:Name="LayoutRoot">


        <Grid>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition MinHeight="260"
                               MaxHeight="260" />
            </Grid.RowDefinitions>


            <Label Grid.Row="0"
                   FontWeight="Bold"
                   Content="Please enter your CodeStash search criteria" />

            <StackPanel Grid.Row="1"
                        Orientation="Horizontal"
                        HorizontalAlignment="Stretch">
                <RadioButton IsChecked="{Binding Path=SelectedSearchType,   
                        Converter={x:Static conv:EnumToBoolConverter.Instance},   
                        ConverterParameter='ByTag'}"
                        Content="By Tag" />
                <RadioButton IsChecked="{Binding Path=SelectedSearchType,   
                        Converter={x:Static conv:EnumToBoolConverter.Instance},   
                        ConverterParameter='ByKeyWord'}"
                        Content="By Key Word" />
                <RadioButton IsChecked="{Binding Path=SelectedSearchType,   
                        Converter={x:Static conv:EnumToBoolConverter.Instance},   
                        ConverterParameter='ByLanguage'}"
                        Content="By Language" />

            </StackPanel>


            <Label Grid.Row="2"
                   Content="Tag" />

            <TextBox Grid.Row="3"
                     core:ControlValidation.ErrorProperty="Tags"
                     core:ControlValidation.ValidationSource="{Binding Validator}"
                     Validation.ErrorTemplate="{x:Static core:ControlValidation.ErrorTemplate}"
                     Text="{Binding Tags}">
            </TextBox>

            <Label Grid.Row="4"
                   Content="Keyword" />

            <TextBox Grid.Row="5"
                     Text="{Binding KeyWord}"
                     core:ControlValidation.ErrorProperty="KeyWord"
                     core:ControlValidation.ValidationSource="{Binding Validator}"
                     Validation.ErrorTemplate="{x:Static core:ControlValidation.ErrorTemplate}"
                     IsEnabled="{Binding IsKeyWordRequired}" />

            <Label Grid.Row="6"
                   Content="Language" />

            <ComboBox Grid.Row="7"
                      IsEnabled="{Binding IsLanguageRequired}"
                      core:ControlValidation.ErrorProperty="SelectedLanguage"
                      core:ControlValidation.ValidationSource="{Binding Validator}"
                      Validation.ErrorTemplate="{x:Static core:ControlValidation.ErrorTemplate}"
                      ItemsSource="{Binding Languages}"
                      SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label Style="{StaticResource comboLabels}"
                               Content="{Binding Language}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>


            <Label Grid.Row="8"
                   Content="Visibility" />

            <ComboBox Grid.Row="9"
                      core:ControlValidation.ErrorProperty="SelectedVisibility"
                      core:ControlValidation.ValidationSource="{Binding Validator}"
                      Validation.ErrorTemplate="{x:Static core:ControlValidation.ErrorTemplate}"
                      ItemsSource="{Binding Visibilities}"
                      SelectedItem="{Binding SelectedVisibility}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label Style="{StaticResource comboLabels}"
                               Content="{Binding}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <Label Grid.Row="10"
                   Content="Rating" />

            <StackPanel Grid.Row="11" Orientation="Horizontal">
                <CheckBox x:Name="includeRating" Margin="5,0,0,0"
                          VerticalAlignment="Center" VerticalContentAlignment="Center"
                          IsChecked="{Binding IncludeRatings}">
                </CheckBox>
                <Label Content="Include Ratings?" />

                <Label Content="Minimum Snippet Ratings" Margin="20,0,0,0" />
                <ComboBox IsEnabled="{Binding ElementName=includeRating, Path=IsChecked}"
                          ItemsSource="{Binding Ratings}"
                          SelectedItem="{Binding Rating}"
                          core:ControlValidation.ErrorProperty="Rating"
                          core:ControlValidation.ValidationSource="{Binding Validator}"
                          Validation.ErrorTemplate="{x:Static core:ControlValidation.ErrorTemplate}"
                          Width="50">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <Label Style="{StaticResource comboLabels}"
                                   Content="{Binding}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
 
            </StackPanel>


            <Button Grid.Row="12"
                    ToolTip="Search CodeStash for snippets"
                    Command="{Binding SearchCommand}">
                <Label Content="Search"
                       HorizontalAlignment="Center"
                       HorizontalContentAlignment="Left"
                       VerticalAlignment="Center"
                       VerticalContentAlignment="Center"
                       Margin="5,0,5,0" />
            </Button>

            <cinch:AsyncHost Grid.Row="13"
                             AsyncState="{Binding Path=AsyncState, Mode=OneWay}">

                <views:SearchResultsView  cinch:AsyncHost.AsyncContentType="Content" />

                <controls:AsyncBusyUserControl cinch:AsyncHost.AsyncContentType="Busy"
                                               AsyncWaitText="{Binding Path=WaitText, Mode=OneWay}"
                                               Visibility="Hidden" />

                <controls:AsyncFailedUserControl cinch:AsyncHost.AsyncContentType="Error"
                                                 Error="{Binding Path=ErrorMessage, Mode=OneWay}"
                                                 Visibility="Hidden" />

            </cinch:AsyncHost>

        </Grid>
    </Grid>

</ui:DialogWindow>
    